/usr/bin/killall soundmeter
sleep 3
FILENAME=$(date "+%Y.%m.%d-%H.%M.%S")
DAY=$(date +"%m.%d")
TIME=$(date +"%T")
arecord -d 60 -D plughw:2,0 -f cd /home/max/multimedia/logs/"$FILENAME".wav

sox /home/max/multimedia/logs/"$FILENAME".wav -n noiseprof noise.prof
sox /home/max/multimedia/logs/"$FILENAME".wav /home/max/multimedia/logs/clean_"$FILENAME".wav noisered noise.prof 0.009

sox -t .wav /home/max/multimedia/logs/clean_"$FILENAME".wav -n stat  2>&1 | tee /home/max/multimedia/logs/clean_"$FILENAME".stat

AMP=$(cat /home/max/multimedia/logs/clean_"$FILENAME".stat |grep 'Maximum amplitude'|awk '{print $3}')
RMS=$(cat /home/max/multimedia/logs/clean_"$FILENAME".stat |grep 'RMS     amplitude'|awk '{print $3}')
DELTA=$(cat /home/max/multimedia/logs/clean_"$FILENAME".stat |grep 'Maximum delta'|awk '{print $3}')
MEAN=$(cat /home/max/multimedia/logs/clean_"$FILENAME".stat |grep 'Mean    norm'|awk '{print $3}')
#sleep 5
python3 /home/max/multimedia/sendfile.py /home/max/multimedia/logs/clean_"$FILENAME".wav
python3 /home/max/multimedia/sendfile.py /home/max/multimedia/logs/clean_"$FILENAME".stat
python3 /home/max/multimedia/message.py amp="$AMP"
#python3 /home/max/multimedia/message.py rms="$RMS"
#python3 /home/max/multimedia/message.py delta="$DELTA"

echo -n "$DAY" >> /home/max/multimedia/log.csv
echo -n "," >> /home/max/multimedia/log.csv
echo -n "$TIME" >> /home/max/multimedia/log.csv
echo -n "," >> /home/max/multimedia/log.csv
echo -n "$AMP" >> /home/max/multimedia/log.csv
echo -n "," >> /home/max/multimedia/log.csv
echo -n "$RMS" >> /home/max/multimedia/log.csv
echo -n "," >> /home/max/multimedia/log.csv
echo -n "$DELTA" >> /home/max/multimedia/log.csv
echo -n "," >> /home/max/multimedia/log.csv
echo "$MEAN" >> /home/max/multimedia/log.csv

bash /home/max/multimedia/graph.sh
/usr/local/bin/soundmeter --profile soundmeter --log /home/max/multimedia/meter.log --daemonize

